package cn.chochy.my.util;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 *
 * @author MLeo
 */
public class ClassGenerics {

    /**
     * 获取父类的泛型类型
     *
     * @param clazz
     * @return String
     */
    public static String fatherClassGenerics(Class clazz) {
        Type type = clazz.getGenericSuperclass();
        if (type instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) type;
            Type[] types = pt.getActualTypeArguments();
            if (types.length > 0) {
                return ((Class) types[0]).getSimpleName();
            }
        }
        return null;
    }

}
